import { h, render } from 'vue'
import Confirm from './Confirm.vue'
export const confirm = (
  content,
  title = '',
  cancelText = '取消',
  confirmText = '确定'
) => {
  return new Promise((resolve, reject) => {
    if (title === '') {
      title = content
    }
    const close = () => {
      render(null, document.body)
    }
    const cancelHandler = () => {
      reject()
      close()
    }
    const confirmHandler = () => {
      resolve()
      close()
    }
    const vnode = h(Confirm, {
      cancelHandler,
      confirmHandler,
      title,
      content,
      cancelText,
      confirmText,
      close
    })
    render(vnode, document.body)
  })
}
